<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="大类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="majorCategories">
              <a-input v-model="model.majorCategories" placeholder="请输入大类"></a-input>
            </a-form-model-item>

            <a-form-model-item label="中类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="middleClass">
              <a-input v-model="model.middleClass" placeholder="请输入中类"></a-input>
            </a-form-model-item>

            <a-form-model-item label="小类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="littleClass">
              <a-input v-model="model.littleClass" placeholder="请输入小类"></a-input>
            </a-form-model-item>

            <a-form-model-item label="长大于" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longGreaterThan">
              <a-input-number v-model="model.longGreaterThan" placeholder="请输入长大于" style="width: 100%" />
            </a-form-model-item>

            <a-form-model-item
              label="长小于等于"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="longLessThanEqual"
            >
              <a-input-number v-model="model.longLessThanEqual" placeholder="请输入长小于等于" style="width: 100%" />
            </a-form-model-item>

            <a-form-model-item label="长余量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longAllowance">
              <a-input v-model="model.longAllowance" placeholder="请输入长余量"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="宽大于" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wideGreaterThan">
              <a-input-number v-model="model.wideGreaterThan" placeholder="请输入宽大于" style="width: 100%" />
            </a-form-model-item>

            <a-form-model-item
              label="宽小于等于"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="wideLessThanEqual"
            >
              <a-input-number v-model="model.wideLessThanEqual" placeholder="请输入宽小于等于" style="width: 100%" />
            </a-form-model-item>

            <a-form-model-item label="宽余量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wideAllowance">
              <a-input v-model="model.wideAllowance" placeholder="请输入宽余量"></a-input>
            </a-form-model-item>

            <a-form-model-item label="高大于" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="highGreaterThan">
              <a-input-number v-model="model.highGreaterThan" placeholder="请输入高大于" style="width: 100%" />
            </a-form-model-item>

            <a-form-model-item
              label="高小于等于"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="highLessThanEqual"
            >
              <a-input-number v-model="model.highLessThanEqual" placeholder="请输入高小于等于" style="width: 100%" />
            </a-form-model-item>

            <a-form-model-item label="高余量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="highAllowance">
              <a-input v-model="model.highAllowance" placeholder="请输入高余量"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="长度公差" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lengthTolerance">
              <a-input v-model="model.lengthTolerance" placeholder="请输长度公差"></a-input>
            </a-form-model-item>

            <a-form-model-item label="宽度公差" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wideTolerance">
              <a-input v-model="model.wideTolerance" placeholder="请输宽度公差"></a-input>
            </a-form-model-item>

            <a-form-model-item label="高度公差" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="highTolerance">
              <a-input v-model="model.highTolerance" placeholder="请输高度公差"></a-input>
            </a-form-model-item>

            <a-form-model-item
              label="是否读基础表"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="isReadBasicTable"
            >
              <a-select style="width: 200px" v-model="model.isReadBasicTable"  allowClear>
                <a-select-option  v-for="(item, index) in isReadBasicTableList" :key="index" :value="item.value">
                  {{ item.text }}
                </a-select-option>
              </a-select>
            </a-form-model-item>

            <a-form-model-item label="是否需要排序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sortOrNot">
              <a-select style="width: 200px" v-model="model.sortOrNot"  allowClear>
                <a-select-option  v-for="(item, index) in sortOrNotList" :key="index" :value="item.value">
                  {{ item.text }}
                </a-select-option>
              </a-select>
            </a-form-model-item>

            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'ChAllowanceForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      // 是否排序,
      sortOrNotList: [],
      //是否读取基础表
      isReadBasicTableList:[],
      model: {
        sortOrNot:'是',
        isReadBasicTable:'是'
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/ch/chAllowance/add',
        edit: '/ch/chAllowance/edit',
        queryById: '/ch/chAllowance/queryById',
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    this.sortOrNotListBtn()
    this.isReadBasicTableBtn()
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    // 是否排序
    sortOrNotListBtn() {
      this.sortOrNotList = [
        {
          value: '是',
          text: '是',
        },
        {
          value: '否',
          text: '否',
        },
      ]
     
    },
    //是否读取基础表
    isReadBasicTableBtn(){
      this.isReadBasicTableList = [
        {
          value: '是',
          text: '是',
        },
        {
          value: '否',
          text: '否',
        },
      ]
    },
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
  },
}
</script>
<style>
  /* .ant-modal-content{
    position: relative;
  
    left: 50%;
    transform: translate(-50%);
    width: 1400px;
  } */
</style>